import com.typesafe.sbt.jse.JsEngineImport.JsEngineKeys.EngineType
import com.typesafe.sbt.less.Import.LessKeys
import com.typesafe.sbt.web.Import.Assets
import play.sbt.PlayImport.PlayKeys
import sbt._
import sbt.Keys._
import sbtassembly.AssemblyPlugin.autoImport._
import sbtassembly.PathList

trait CustomSettings {

  val lessSettings = Seq(
    includeFilter in (Assets, LessKeys.less) := "*.less",
    excludeFilter in (Assets, LessKeys.less) := "_*.less"
  )

  val jsEngineSettings = Seq(
    com.typesafe.sbt.jse.JsEngineImport.JsEngineKeys.engineType := EngineType.Trireme
  )

  val scalaSettings = Seq(
    //scalacOptions ++= Seq("-feature", "-deprecation", "-Ywarn-unused-import", "-language:existentials")
    scalacOptions ++= Seq("-feature", "-deprecation", "-Ypartial-unification"),
    scalaVersion := "2.12.5"
  )

  val assemblySettings = sbtassembly.AssemblyPlugin.assemblySettings ++ Seq(
    //mainClass in assembly := Some("play.core.server.ProdServerStart"),
    mainClass in assembly := Some("runner.Runner"),
    assemblyMergeStrategy in assembly := {
      val old = (assemblyMergeStrategy in assembly).value

      { pathStr =>
        pathStr match {
          case "application.conf" => MergeStrategy.discard
          case "reference.conf" => MergeStrategy.concat
          case PathList("META-INF", "terracotta", "public-api-types") => MergeStrategy.concat
          case PathList("play", "reference-overrides.conf") => MergeStrategy.concat
          case PathList("META-INF", "spring.tooling") => MergeStrategy.discard
          case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.first
          case PathList("ahc-default.properties") => MergeStrategy.first
          //pdf 配置开始
          //case PathList("resources", "schema", _*) => MergeStrategy.concat
          //case PathList("resources", "conf", "xhtmlrenderer.conf") => MergeStrategy.concat
          //case PathList("resources", "css", "XhtmlNamespaceHandler.css") => MergeStrategy.concat
          //pdf 配置结束
          case x => old(x)
        }
      }
    },
    fullClasspath in assembly += Attributed.blank(PlayKeys.playPackageAssets.value)
  )

  val jdkPackagerSettings = {

    import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport._
    import com.typesafe.sbt.packager.windows.WindowsPlugin.autoImport._
    import com.typesafe.sbt.SbtNativePackager.autoImport._
    import com.typesafe.sbt.packager.jdkpackager.JDKPackagerPlugin.autoImport._

    Seq(
      mappings in Windows := (mappings in Universal).value,
      // general package information (can be scoped to Windows)
      maintainer := "djx314",
      packageSummary := "xPhoto",
      packageDescription := """xPhoto.""",
      // wix build information
      wixProductId in Windows := "ce07be71-510d-414a-92d4-dff47631848a",
      wixProductUpgradeId in Windows := "4552fb0e-e257-4dbd-9ecb-dba9dbacf424",
      jdkPackagerType := "exe",
      mainClass in ThisBuild := Some("play.core.server.ProdServerStart")
    )

  }

  val compilerSettings = addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)

}

object CustomSettings extends CustomSettings